package com.handinfo.android.ui.window;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.game.GameActor;
import com.handinfo.android.game.Role;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.SimpleRole;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWPopMenu;



public class UICheckPeople implements IUIWindows{

	private Bitmap[] m_cp_bm = new Bitmap[2];
	private DWImageBox[] m_cp_ib = new DWImageBox[1];
	private DWPopMenu m_cp_pm = null;
	private String[] m_cp_caidan = {"密语","交易","查看","加为好友","添加黑名单","邀请组队","发布通缉令"};
	private String[] m_cp_caidan01 = {"密语","交易","查看","加为好友","添加黑名单","邀请组队","收徒"};
	private String[] m_cp_caidan02 = {"密语","交易","查看","加为好友","添加黑名单","邀请组队","拜师"};
	private String[] m_cp_caidan03 = {"密语","交易","查看","加为好友","添加黑名单","邀请组队"};

	private byte m_cp_beijing = 1;//菜单选项的背景
	private Bitmap m_bm_anxia = null;
	

	public boolean m_miyu_flag = true;///判断是否点击密语这项的布尔变量
	private void checkedCaidan(){
		//社交菜单选项
		GameActor ar = DWGameManager.getInstance().m_role.m_targetActor;
		if(ar.m_faction == DWGameManager.getInstance().m_role.m_faction){//同一阵营
			if (ar.m_lv <= DWGameManager.getInstance().m_role.m_shitu_tudilv) {// 目标等级是徒弟
				if (DWGameManager.getInstance().m_role.m_lv >= DWGameManager.getInstance().m_role.m_shitu_laoshi) {// 自己是师父
					m_cp_pm = new DWPopMenu(m_cp_caidan01,m_cp_bm[m_cp_beijing]);
				} else {
					m_cp_pm = new DWPopMenu(m_cp_caidan03,m_cp_bm[m_cp_beijing]);
				}
			}else if(ar.m_lv >= DWGameManager.getInstance().m_role.m_shitu_laoshi){//目标是老师
				if(DWGameManager.getInstance().m_role.m_lv <= DWGameManager.getInstance().m_role.m_shitu_tudilv){
					m_cp_pm = new DWPopMenu(m_cp_caidan02, m_cp_bm[m_cp_beijing]);
				}else{
					m_cp_pm = new DWPopMenu(m_cp_caidan03, m_cp_bm[m_cp_beijing]);
				}
				
			}else{
				m_cp_pm = new DWPopMenu(m_cp_caidan03, m_cp_bm[m_cp_beijing]);
			}			
		}else{
			m_cp_pm = new DWPopMenu(m_cp_caidan, m_cp_bm[m_cp_beijing]);
		}
				
		m_cp_pm.setDownImage(m_bm_anxia);
//		m_cp_pm.setNearAnchor(UIMain.m_Uimain_Frame, ownAnchor, targetAnchor, interspaceX, interspaceY)
		UIMain.m_Uimain_Frame.addControl(m_cp_pm);
		
		m_cp_pm.addListener(new DWListener() {
			
			public void OnDoubleClick() {
			}
			
			public void OnClick() {
				UIMain.m_Uimain_Frame.removeControl(m_cp_pm);
				int m_si_index = m_cp_pm.getIndex();
				GameActor ar = DWGameManager.getInstance().m_role.m_targetActor;
				switch(m_si_index){
				case 0://密语
					m_miyu_flag = false;
					ChatPrivate(ar.m_gameId,ar.m_name);
					break;
				case 1://交易
					UIWindows.getInstance().m_exchang.setActor(ar.m_gameId,ar.m_name);
					UIWindows.getInstance().m_exchang.open((byte)0);					
					break;
				case 2://查看
					DWGameManager.getInstance().getSendMessage().sendSeeOtherRoleInfo(ar.m_gameId);
					break;
				case 3://添加好友			
					DWGameManager.getInstance().getSendMessage().sendSocialAddForName(UISocial.SOCIAL_TYPE_FRIEND, ar.m_name);
					break;
				case 4://添加黑名单
					DWGameManager.getInstance().getSendMessage().sendSocialAddForName(UISocial.SOCIAL_TYPE_BLACKLIST, ar.m_name);
					break;
				case 5://邀请组队
					DWGameManager.getInstance().getSendMessage().sendTeamRequest(ar.m_gameId);
					break;
				case 6://拜师
					if(ar.m_faction == DWGameManager.getInstance().m_role.m_faction){
						DWGameManager.getInstance().getSendMessage().sendBaiShi(ar.m_gameId);
					}else{//发布通缉令
						UIWindows.getInstance().m_warrant.open((byte) 0);
						UIWindows.getInstance().m_warrant.setMessage(ar.m_gameId, ar.m_name);
					}
					break;
				}
			}
		});
	}
	
	
	public void init() {
		m_cp_bm[m_cp_beijing] = UIWindows.createImage("/img/newui/anniu_6.gnp");
		m_bm_anxia = UIWindows.createImage("/img/newui/anniu_6ax.gnp");
		
	}


	public void open(byte index) {
		checkedCaidan();
	}


	public void close(byte index) {

	}


	public void dispose() {
	}


	public void logic()
	{
		// TODO Auto-generated method stub
		
	}

	/**
	 * 私聊
	 * @param id
	 * @param name
	 */
	public void ChatPrivate(long id,String name){
		if (id != DWGameManager.getInstance().m_role.m_gameId)
		{
			UIWindows.getInstance().m_liaotian.open((byte) 0);
			UIWindows.getInstance().m_liaotian.m_tabcontrol.setSelectPage(6);
			UIWindows.getInstance().m_liaotian.m_pindao_but.setName("私聊");
			UIWindows.getInstance().m_liaotian.m_inputbox
			.setText(name+ ": ");
			UIWindows.getInstance().m_liaotian.ID(id);
			UIWindows.getInstance().m_liaotian.Name(name);
		}
		else
		{
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
					"抱歉，不能和自己聊天。");
		}
	}

}
